/*global soundManager: false*/
/*
 * #depends subsonic-folder-tree.js
 * #depends subsonic-folderview.js
 * #depends subsonic-trackgrid.js
 * #depends subsonic-coverflow.js
 */
Ext.onReady(function(){	
	if (Ext.isDefined(Ext.ux.mattgoldspink.subsonic.notYetLoggedIn)) {
        Ext.ux.mattgoldspink.subsonic.Login();
	}
    var viewport = new Ext.Viewport({
        layout: 'border',
        items: [
            new Ext.ux.mattgoldspink.subsonic.FolderTreePanel({
                width: 200,
                split: true,
                flex: 1,
                id: 'leftbar',
                region: 'west'
            }),
            {
                layout: 'card',
                ref: 'corepanel',
                xtype: 'container',
                plugins: ['msgbus'],
                activeItem: 1,
                region: 'center',
                stateful: true,
                stateId: 'corepanel',
                stateEvents: ['afterlayout'],
                deferredRender: true,
                getState: function(){
                    return {
                        activeItem: this.layout.activeItem.id
                    };
                },
                applyState: function(state) {
                    this.activeItem  = state.activeItem;
                },
                items:    [
                    new Ext.ux.mattgoldspink.subsonic.TrackGrid({
                        id: 'gridview'
                    }),
                    new Ext.ux.mattgoldspink.subsonic.FolderView({
                        id: 'albumview'            
                    }),
                    new Ext.ux.mattgoldspink.subsonic.CoverFlow({
                        id: 'coverflow'        
                    })
                ],
                listeners: {
                    afterrender: function(){
                        this.subscribe('subsonic.view.change', {fn: function(subject, view) {
                            this.layout.setActiveItem(view);
                        }, scope: this});
                    }
                }
            },
            new Ext.ux.mattgoldspink.subsonic.PlayerPanel({
                region: 'north'
            }),
            new Ext.ux.mattgoldspink.subsonic.BottomBar({
                region: 'south'
            })
        ]
    });
});
